POV-Ray : Newsgroups : povray.programming : Vectors in C++ : Re: Vectors in C++ Server Time
6 Oct 2024 15:17:42 EDT (-0400)
  Re: Vectors in C++  
From: Micha Riser
Date: 17 Dec 2002 14:35:00
Message: <3dff7c63@news.povray.org>
Christopher James Huff wrote:
>> Sometimes there is also an additional temporary variable created.
> 
> You are micro-optimizing...though I am sometimes guilty of that too.
> A good compiler can often figure out the most efficient way to compile
> the code.

Well, that's probably quite true.. I am "unoptimizing" by and by things for 
sake of a better abstraction. And I have already add the + operator to the 
colour classes when I had used a nasty integration formula for the media 
stuff.

> 
>> will have to be tranlated by the compiler to
>>  tmp = c;
>>  tmp += b;
>>  a += tmp;
>> as it cannot assume that (a+b)+c is the same as a+(b+c). On the other
>> hand
>>  a.add(b); a.add(c);
>> does not need a temporary variable.
> 
> a += b; a += c;
> or:
> (a += b) += c;
> 
> No temporaries.

But you probably wouldn't write it like this when you had the + available.

> The version using operator overloading is much easier to read, and the
> compiler could probably optimize away any significant differences.
> 

I still think the programmer is more forced to think about the best 
operation sequence when one has to apply them one by one and cannot just 
put lengths of forumlas there.

- Micha

-- 
objects.povworld.org - The POV-Ray Objects Collection
book.povworld.org    - The POV-Ray Book Project


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.